var app = getApp();
const util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentPage: 1,
    activityId: null,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      activityId: options.activityId
    })
    //加载排行榜数据
    this.getRank(options.activityId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getRank(this.data.activityId);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let url = util.getCurrentPageUrlWithArgs();
    if (url.indexOf('?') > -1) {
      url += '&fid=' + app.globalData.fid + '&fidEnc=' + app.globalData.fidEnc;
    } else {
      url += '?fid=' + app.globalData.fid + '&fidEnc=' + app.globalData.fidEnc;
    }
    if (options.from == "menu") {
      return {
        title: app.globalData.site.name,
        path: url
      }
    }
  },

  getRank: function(activityId){
    var that  = this;
    wx.request({
      url: app.globalData.activityHost + '/services/activityaction/listActivityProductionWx',
      data: {
        activityId: that.data.activityId,
        currentPage: that.data.currentPage,
        pageSize: 10,
        orderType: 2
      },
      success: function(res){
        console.log(res);
        if(res.data.result == "0"){
          that.setData({
            list: that.data.list.concat(res.data.obj.data),
            currentPage: that.data.currentPage + 1
          })
        }else{
          console.log("加载活动出错了！")
        }
      },
      fail: function(){
        console.log("加载排行榜出错");
      }
    })
  },

  /**
   * 跳转到详情页
   */
  gotoDetail: function(e){
    console.log(e);
    var type = e.currentTarget.dataset.type;
    var activityId = e.currentTarget.dataset.id;
    var uid = wx.getStorageSync('cxid');
    var fid = app.globalData.fid;
    wx.navigateTo({
      url: '/pages/link/link?url=https://videoshequ3.chaoxing.com/miniprogram/play&type=' + type + "&activityId=" + activityId + "&uid=" + uid + "&fid=" + fid,
    })
  },

})